<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /*
    finally方法 无论调用promise实列成功或者失败都能进入finally中的回调函数执行
    finally不接受promise实列的值
    finally的返回值默认穿透 finally的返回值和调用finally的promise实列保持一致
    当finally中的回调函数返回一个失败promise实例，finally的返回值和这个失败promise实列的值保持一致
    当finally中的回调函数报错 finally返回失败的promise的实列 值为报错的信息
    */
    const p1 = new Promise((resolve, reject) => {
      //throw new Error('错误')
      try {
        console.log('获取数据A');
        
        setTimeout(() => {
          console.log('A数据成功');
          resolve('1')
        }, 2000)
      } catch (e) {
        console.log(e.message);
      }
    })

    p1.then((v) => {
      console.log(v);
    })

    const p2 = p1.finally((reason) => {
     return new Promise((resolve,reject)=>{
      resolve()
     })
    })

    console.log('p1', p1);
    console.log('p2', p2);
  </script>
</body>

</html>
</body>
</html>